#include "Player.h"

#include "DirectXStuff.h"
#include "MatrixStack.h"
#include "Network.h"
#include "NetworkController.h"
#include "PlayerController.h"

Player::Player(short reference, Mesh* _Mesh, bool controlled) : m_ignoreController(controlled)
{
	//CHRIS::Make this automatically create a network controller
	m_controller = new NetworkController(m_data.GetSize(), reference);
	m_Mesh = _Mesh;

	m_Alive = true;

	//If this player is controlled locally, create a local controller
	if(controlled)
	{
		m_pController = new PlayerController(this);
	}
}

void Player::ToTick(long tick)
{
	if( m_controller->GetData(tick) != NULL)
	{
		char* a = (char*)(m_controller->GetData(tick)->c_str());
		a >> *this;
	}
}


Player::~Player() {delete m_Mesh;}

void Player::Update(float deltaT)
{
	if(m_Cube != NULL)
	{
		m_Cube->m_Matrix.m[3][0] = m_data.data.Matrix.m[3][0];
		m_Cube->m_Matrix.m[3][1] = m_data.data.Matrix.m[3][1];
		m_Cube->m_Matrix.m[3][2] = m_data.data.Matrix.m[3][2];
	}
}